package com.photobucket.webapi.service
{
/*        import flexunit.framework.TestCase;
        import flexunit.framework.TestSuite;
        */
        import flexunit.framework.TestCase;
        import flexunit.framework.TestSuite;        
        import com.photobucket.webapi.interfaces.IService;
        import com.photobucket.webapi.oauth.IOAuthRequest;
        import com.photobucket.webapi.oauth.OAuthRequest;
        import com.photobucket.webapi.oauth.oauth_internal;        

        use namespace oauth_internal;

		public class PhotobucketServiceTest extends TestCase {

			public function PhotobucketServiceTest(methodName:String = null) {
				super(methodName);
			}

			public function testEncodedURL():void {
				var service:PhotobucketService = PhotobucketService.getInstance() as PhotobucketService;
				var inUrl:String = "http://api.photobucket.com";
				var outUrl:String = service.getEncodedURL(inUrl);
				assertEquals("URL Encoded Properly", "http%3A%2F%2Fapi.photobucket.com", outUrl);
				inUrl = "http://api123.photobucket.com";
				outUrl = service.getEncodedURL(inUrl);
				assertEquals("URL Encoded Properly and set to api.photobucket.com", "http%3A%2F%2Fapi.photobucket.com", outUrl);
			}

			public function testSignRequestLoggedOut():void {
				var service:PhotobucketService = PhotobucketService.getInstance() as PhotobucketService;
				service.oauth_consumer_key = "consumerkey";
				service.oauth_consumer_secret = "consumersecret";
				service.oauth_token = "oauthtoken";
				service.oauth_token_secret = "oauthtokensecret";
				var request:IOAuthRequest = new OAuthRequest();
				request.method = "GET";
				request.needsLogin = false;
				request.url = "http://api123.photobucket.com/action/ident";
				request.addParameter("param1", "value");
				request.addParameter("param2", "value");
				service.signRequest(request);
				var paramString:String = request.parameterString;
				assertContained("Consumer added to request", "oauth_consumer_key=consumerkey", paramString);
				assertContained("Timestamp added to request", "oauth_timestamp=", paramString);
				assertContained("Nonce added to request", "oauth_nonce=", paramString);
				assertContained("Version added to request", "oauth_version=1.0", paramString);
				assertContained("Signature method added to request", "oauth_signature_method=HMAC-SHA1", paramString);
				assertNotContained("Token Not Added", "oauth_token", paramString);
				assertNotContained("Secrets not added", "secret", paramString);
				assertContained("_Method Added", "_method=GET", paramString);
				assertContained("format Added", "format=XML", paramString);
			}
			
			public function testURLServerUrls():void {
				var service:PhotobucketService = PhotobucketService.getInstance() as PhotobucketService;
				var url:String;
				url = service.getAPIServer(null);
				assertEquals("Null urls should return default url", "http://api.photobucket.com", url);
				url = service.getAPIServer("http://api123.photobucket.com");
				assertEquals("Urls should pass though if no specific server set", "http://api123.photobucket.com", url);
				service.setAPIRoot("http://api431.photobucket.com");
				url = service.getAPIServer("http://api123.photobucket.com");
				assertEquals("Once the api server is set it should be sticky", "http://api431.photobucket.com", url);
			}

		}
}